<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">

		<%include("/common/include.html"){}%>
	</head>

	<body class="easyui-layout">
			<table id="daySalesTable" class="easyui-datagrid" style="height:100%;">
			<thead frozen="true">
						<tr>
<!-- 							<th data-options="field:'customerid',width:100,align:'center',hidden:true">customerid</th> -->
							<th data-options="field:'date',width:100,align:'center'">日期</th>
							<th data-options="field:'newadd',width:30,align:'center'" formatter='formatNewadd'>新增</th>
							<th data-options="field:'name',width:50,align:'center'" formatter='formatName'>姓名</th>
							<th data-options="field:'intotime',width:80,align:'center'">首次到店日期</th>
						</tr>
					</thead>
					<thead>
						<tr>
						<th data-options="field:'producttotalprice',width:50,align:'center',rowspan:2" >产品<br>金额合计</th>
							<th data-options="field:'sum',width:80,align:'center',rowspan:2" >总计<br>(减重+产品)</th>
							<th data-options="field:'singlelc',width:100,align:'center',colspan:2" >单疗程</th>
							<th data-options="field:'normlc',width:100,align:'center',colspan:3" >标准疗程</th>
							<th data-options="field:'uplc',width:100,align:'center',colspan:2" >转疗程</th>
							<th data-options="field:'lctotalprice',width:50,align:'center',rowspan:2" formatter='formatLcTotalPrice'>减重<br>金额合计</th>
							<%if(!isEmpty(products)){%>
								<%for(product in products){%>
									<th data-options="field:'${product.bh! }',width:80,align:'center',colspan:2">${product.name! }</th>
								<%}%>
							<%}%>
							
						</tr>
						<tr>
							<th data-options="field:'singlelc_peoplenum',width:50,align:'center'" >人数</th>
<!-- 							<th data-options="field:'singlelc_unitprice',width:50,align:'center'" >单价(元)</th> -->
							<th data-options="field:'singlelc_totalprice',width:50,align:'center'" >金额(元)</th>
							<th data-options="field:'normlc_peoplenum',width:50,align:'center'" >人数</th>
							<th data-options="field:'normlc_lcnum',width:50,align:'center'" >疗程数</th>
							<!-- <th data-options="field:'normlc_unitprice',width:50,align:'center'" >单价(元)</th> -->
							<th data-options="field:'normlc_totalprice',width:50,align:'center'" >金额(元)</th>
							<th data-options="field:'uplc_peoplenum',width:50,align:'center'" >人数</th>
							<th data-options="field:'uplc_lcnum',width:50,align:'center'" >疗程数</th>
							<th data-options="field:'uplc_totalprice',width:50,align:'center'" >金额(元)</th>
							<%if(!isEmpty(products)){%>
								<%for(product in products){%>
									<th data-options="field:'${product.bh! }_num',width:80,align:'center'">数量</th>
									<th data-options="field:'${product.bh! }_price',width:80,align:'center'">金额</th>
								<%}%>
							<%}%>
							
						</tr>
					</thead>
			</table>
			<div id="saletb" >
			
				<label class="label-top" style="width: 100%; display: block;">日期</label>
				<input id="curDate" name="curDate" value="${date ! }" class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" />
				<input name="organIds" id="organIds" type="hidden" value="${curOrgan.ids! }">
			</div>
			
		
		<script type="text/javascript">
			$(document).ready(function () {
				
				//加载数据表格
				initDaySalesTable();
				$('#curDate').datebox({
					onChange: function(date){
						
						initDaySalesTable();
					}
				});
			});
			function initDaySalesTable(){
				var curDate = $("#curDate").val();
				var orgianIds = $("#organIds").val();
				$('#daySalesTable').datagrid({
					cls: "theme-datagrid",
					toolbar: '#saletb',
					singleSelect: true,
					rownumbers: true, //显示序号
					url: "${cxt!}/daySalesStatistic/view",
					queryParams: {
						'curDate': curDate,
						'orgianIds':orgianIds
					},
				    method: 'post',
					collapsible: true,
					onLoadSuccess:function(){
						var rows = $('#daySalesTable').datagrid('getRows');
							$('#daySalesTable').datagrid('mergeCells',{
								index: rows.length - 1,
								field: 'date',
								colspan: 4
							});
					},
					onClickRow:function(rowIndex,rowData){
					}
				});
			}
			
			//指定列求和
	        function compute(colName) {
	             var rows = $('#daySalesTable').datagrid('getRows');
	             var total = 0;
	             for (var i = 0; i < rows.length; i++) {
	            	 if(typeof(rows[i][colName]) != 'undefined'){
	            		 total += parseFloat(rows[i][colName]);
	            	 }
	             }
	             if(total > 0){
	            	 return total;
	             }else{
	            	 return '';
	             }
	         }
	      	//减重求和
			function formatLcTotalPrice(value,row){
				var total = 0;
				if(typeof(row.singlelc_totalprice) != 'undefined'){
           		 	total += parseFloat(row.singlelc_totalprice);
           	 	}
				if(typeof(row.normlc_totalprice) != 'undefined'){
           		 	total += parseFloat(row.normlc_totalprice);
           	 	}
				if(typeof(row.uplc_totalprice) != 'undefined'){
           		 	total += parseFloat(row.uplc_totalprice);
           	 	}
				if(total > 0){
	            	return total;
	            }else{
	            	return '';
	            }
			}
			//格式化产品求和
			function formatProductTotalPrice(value,row){
				var sum = row.producttotalprice;
				if(sum == 0){
					return '';
				}else{
					return sum;
				}
			}
			//减重+产品求和
			function formatSum(value,row){
				var total = 0;
				if(typeof(row.singlelc_totalprice) != 'undefined' && row.singlelc_totalprice != ''){
           		 	total += parseFloat(row.singlelc_totalprice);
           	 	}
				if(typeof(row.normlc_totalprice) != 'undefined' && row.normlc_totalprice != ''){
           		 	total += parseFloat(row.normlc_totalprice);
           	 	}
				if(typeof(row.uplc_totalprice) != 'undefined' && row.uplc_totalprice != ''){
           		 	total += parseFloat(row.uplc_totalprice);
           	 	}
				if(typeof(row.producttotalprice) != 'undefined' && row.producttotalprice != ''){
           		 	total += parseFloat(row.producttotalprice);
           	 	}
				if(total > 0){
	            	return total;
	            }else{
	            	return '';
	            }
			}
			//格式化新增
			function formatNewadd(value,row){
				if(row.intotime == row.date){
					return '<span style="color:#ff954e;">是</span>'
				}else{
					return '否';
				}
			}
			//格式化顾客name
			function formatName(value,row){
				var ids = row.customerid;
				return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
			}
			//查看顾客详细信息
			function lookCustomerInfo(ids){
				loadViewDialog('查看顾客详细信息', '${cxt!}/customerInfoStatistic/lookCustomerInfo?ids=' + ids);
			}
			
			

		

		</script>
	</body>
</html>